﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace WindowsGame3
{
    public class Sorteio
    {
        Texture2D textura1;
        Rectangle rectA = new Rectangle(0, 0, 50, 50);
        Random randPosicao = new Random();
        List<Texture2D> Texturas;
        List<Rectangle> Retangulos;
        Random rndTexture;
        int valorSorteio, tempo_atual, tempo_maximo, fator_movimento;


        public Sorteio(ContentManager Content)
        {
            Texturas = new List<Texture2D>();
            Retangulos = new List<Rectangle>();
        
            textura1 = Content.Load<Texture2D>("Untitled-2");

            rndTexture = new Random();

            tempo_atual = 0;
            tempo_maximo = 1200;
            fator_movimento = 2;
        }
        public void Update(GameTime gameTime)
        {
            tempo_atual += gameTime.ElapsedGameTime.Milliseconds;

            if (tempo_atual == tempo_maximo)
            {
                ListaDesenho();
                tempo_atual = 0;
            }

            if (Retangulos == null)
                return;
            for (int g = 0; g < Retangulos.Count; g++)
                Retangulos[g] = new Rectangle((int)Retangulos.ElementAt(g).X - 1, (int)Retangulos.ElementAt(g).Y,
                (int)Retangulos.ElementAt(g).Width, (int)Retangulos.ElementAt(g).Height);

        }
        private Texture2D RetornaTextura(int valorTextura)
        {
            //switch (valorTextura)
            //{
            //    case 1:
                    return textura1;
                //default:
                //    return textura1;
            //}
        }
        private Rectangle Posicao(int fatorPosicao)
        {
            rectA = new Rectangle(600, 200 * fatorPosicao,  25, 25);
            return rectA;
        }
        public void ListaDesenho()
        {
            valorSorteio = rndTexture.Next(0, 3);
            Texturas.Add(RetornaTextura(valorSorteio));

            valorSorteio = rndTexture.Next(1, 4);
            Retangulos.Add(Posicao(valorSorteio));

        }

        public void Draw(SpriteBatch spriteBatch)
        {
            if (Texturas == null)
                return;
            for (int i = 0; i < Texturas.Count; i++)
                spriteBatch.Draw(Texturas.ElementAt(i), Retangulos.ElementAt(i), Color.White);
        }
    }
}
